
#ifndef __KLIB_VAR_H__
#define __KLIB_VAR_H__

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum _datatype_t {
	DATA_TYPE_CHAR			= 1,
	DATA_TYPE_BYTE			= 2,
	DATA_TYPE_SHORT			= 3,
	DATA_TYPE_USHORT		= 4,
	DATA_TYPE_INT			= 5,
	DATA_TYPE_UINT			= 6,
	DATA_TYPE_LONG			= 7,
	DATA_TYPE_ULONG			= 8,
	DATA_TYPE_LONGLONG		= 9,
	DATA_TYPE_TIME			= 10,
	DATA_TYPE_SIZE			= 11,
	DATA_TYPE_FLOAT			= 12,
	DATA_TYPE_DOUBLE		= 13,
	DATA_TYPE_LONGDOUBLE	= 14,
	DATA_TYPE_CSTR			= 15,
	DATA_TYPE_PTR			= 16
} datatype_t;

typedef union _value_t {
	char			charVal;
	unsigned char	byteVal;
	short			shortVal;
	unsigned short	ushortVal;
	int				intVal;
	unsigned int	uintVal;
	long			longVal;
	unsigned long	ulongVal;
	long long		longlongVal;
	time_t			timeVal;
	size_t			sizeVal;
	float			floatVal;
	double			doubleVal;
	long double		longdoubleVal;
	char *			cstrVal;
	void *			ptrVal;
	unsigned char	bytes[sizeof(long double)];
} value_t;

typedef struct _var_t {
	value_t			value;
	datatype_t		datatype : 7;
	unsigned int	isnull : 1;
	unsigned int	reserved : 24;
} var_t;

var_t var_char(char value);
var_t var_uchar(unsigned char value);
var_t var_short(short value);
var_t var_ushort(unsigned short value);
var_t var_int(int value);
var_t var_uint(unsigned int value);
var_t var_long(long value);
var_t var_ulong(unsigned long value);
var_t var_longlong(long long value);
var_t var_time(time_t value);
var_t var_size(size_t value);
var_t var_float(float value);
var_t var_double(double value);
var_t var_longdouble(long double value);
var_t var_cstr(char *value);
var_t var_ptr(void *value);
var_t *var_create(var_t value);
const char *tostring(var_t *var);
int var_compare(var_t *v1, var_t *v2);

#ifdef __cplusplus
}
#endif

#endif